package com.matt.repository;

import com.matt.domain.LeaveRecord;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import java.util.Date;
import java.util.List;


public interface LeaveRecordRepository extends JpaRepository<LeaveRecord, String> , JpaSpecificationExecutor<LeaveRecord> {

    LeaveRecord findFirstByTeacherIdAndLeaveDateBetweenAndLeaveTypeAndDeletedAndStatusNot(String teacherId, Date begin, Date end, Integer leaveType, boolean flag, Integer noStatus);

    LeaveRecord findFirstByTeacherIdAndLeaveDateBetweenAndDeletedAndStatusNot(String teacherId, Date begin, Date end, boolean flag, Integer noStatus);

    LeaveRecord findFirstByChildrenIdAndLeaveDateBetweenAndLeaveTypeAndDeletedAndStatusNot(String childrenId, Date begin, Date end, Integer leaveType, boolean flag, Integer noStatus);

    LeaveRecord findFirstByChildrenIdAndLeaveDateBetweenAndDeletedAndStatusNot(String childrenId, Date begin, Date end, boolean flag, Integer noStatus);

    List<LeaveRecord> findAllByTeacherIdAndLeaveDateBetweenAndDeletedOrderByCreatedDesc(String teacherId, Date begin, Date end,boolean flag);

    Page<LeaveRecord> findAllByAreaIdAndSourceAndChildrenIdInAndDeletedOrderByCreatedDesc(String areaId, String source, List<String> childrenIds, boolean deleted, Pageable pageable);

    Page<LeaveRecord> findAllByAreaIdAndTeacherIdAndDeletedOrderByCreatedDesc(String areaId, String teacherId, boolean deleted, Pageable pageable);

    Page<LeaveRecord> findAllByAreaIdAndSourceAndDeletedOrderByCreatedDesc(String areaId, String source, boolean deleted, Pageable pageable);
    //                    predicates.add(criteriaBuilder.and(criteriaBuilder.equal(root.get("areaId"), areaId)));
    //
    //                    predicates.add(criteriaBuilder.and(criteriaBuilder.equal(root.get("source"), source)));
    //                    predicates.add(criteriaBuilder.and(criteriaBuilder.equal(root.get("deleted"),false )));
    //
    //                    Expression<String> exp = root.<String>get("childrenId");
}
